﻿Imports System
Imports System.Windows.Forms
Imports System.Data

Public Class FrmChonSheetExcel
    Private _DtbSheetName As DataTable
    Public Property DtbSheetName() As DataTable
        Get
            Return _DtbSheetName
        End Get
        Set(ByVal value As DataTable)
            _DtbSheetName = value
        End Set
    End Property

    Private _SheetName As String
    Public Property SheetName() As String
        Get
            Return _SheetName
        End Get
        Set(ByVal value As String)
            _SheetName = value
        End Set
    End Property

    Private Sub FrmChonSheetExcel_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If (e.Modifiers = GetKeyModifide("EXIT") And _
     e.KeyCode = GetKeyCode2("EXIT")) Or _
     (e.KeyCode = GetKeyCode("EXIT")) Then
            btnHuyBo_Click(Nothing, Nothing)
        End If

        If (e.Modifiers = GetKeyModifide("ACCEPT") And _
     e.KeyCode = GetKeyCode2("ACCEPT")) Or _
     (e.KeyCode = GetKeyCode("ACCEPT")) Then
            If btnChapNhan.Enabled And btnChapNhan.Visible Then
                btnChapNhan_Click(Nothing, Nothing)
            End If
        End If
    End Sub

    Private Sub FrmChonSheetExcel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        grc.DataSource = DtbSheetName
        grv.FocusedRowHandle = 0
        grv.Focus()
    End Sub

    Private Sub btnHuyBo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHuyBo.Click
        SheetName = ""
        Me.Close()
    End Sub

    Private Sub btnChapNhan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChapNhan.Click
        If grv.FocusedRowHandle < 0 Then
            Return
        End If
        SheetName = CStr(grv.GetFocusedRowCellValue(colLstSheetName))
        Me.Close()
    End Sub

    Private Sub grv_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grv.KeyDown
        If e.KeyCode = Keys.Enter Then
            If btnChapNhan.Enabled And btnChapNhan.Visible Then
                btnChapNhan_Click(Nothing, Nothing)
            End If
        End If
    End Sub
End Class